package com.bot.snakeRunningSystem.Controller;

import com.bot.snakeRunningSystem.Service.SnakeRunningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
public class SnakeRunningController {
    @Autowired
    private SnakeRunningService snakeRunningService;

    @PostMapping("/snake/add/")
    public String addSnake(@RequestParam MultiValueMap<String, String> data) {
        Integer userId = Integer.parseInt(Objects.requireNonNull(data.getFirst("user_id")));
        String botCode = data.getFirst("snake_code");
        String input = data.getFirst("input");
        return snakeRunningService.addSnake(userId, botCode, input);
    }
}
